package com.csxh.eshop.bean;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;

@Entity(name="tb_student")
public class Student implements Serializable {

	private Integer id;
	private String name;
	private IdCard idCard;
	
	private Set<Course> courseSet=new HashSet<Course>();
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(length=20,nullable=false)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToMany(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH,CascadeType.MERGE})
	@JoinTable(
			name="tb_student_course",
			joinColumns=@JoinColumn(name="student_id",referencedColumnName="id"),
			inverseJoinColumns=@JoinColumn(name="course_id",referencedColumnName="id")
			)
	
	public Set<Course> getCourseSet() {
		return courseSet;
	}
	
	public void setCourseSet(Set<Course> courseSet) {
		this.courseSet = courseSet;
	}
	
	@OneToOne(optional=true,mappedBy="student")
	public IdCard getIdCard() {
		return idCard;
	}
	
	public void setIdCard(IdCard idCard) {
		this.idCard = idCard;
	}
}
